/*****************************************************************************
 *   Copyright 2005 Tim A Wang
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 ****************************************************************************/
package com.jb.web.renderer;

import com.jb.web.bean.content.Movie;
import com.jb.web.context.WebContext;

import com.jb.faces.component.UIComponent;


public class MovieRenderer extends RendererImpl {
    /**
     * DOCUMENT ME!
     *
     * @param pCtx DOCUMENT ME!
     * @param itemToRender DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public StringBuffer renderBegin(WebContext pCtx, UIComponent itemToRender) {
        Movie hItem = (Movie) itemToRender;
        StringBuffer htmlBuffer = new StringBuffer("");
        htmlBuffer.append("<div ").append(getEditScript(pCtx, hItem))
                  .append(addTagProperty("style", hItem.getStyle(pCtx), null))
                  .append(addTagProperty("class", hItem.getStyleClass(), null)).append(" >");

        String loc = hItem.getLocation();

        if (!isEmptyString(loc) && isVisible(pCtx, hItem)&& pCtx.isRunTime()) {
            loc = evaluate(pCtx, hItem, loc);
            htmlBuffer.append(
                "<OBJECT CLASSID=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" CODEBASE=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\"")
                      .append(addTagProperty("WIDTH",hItem.getWidth(),"300px"))
                      .append(addTagProperty("HEIGHT",hItem.getHeight(),"200px"))
                      .append(hItem.getHeight()).append("\"").append(">").append("<PARAM NAME=\"movie\" VALUE=\"")
                      .append(hItem.getLocation()).append("\">").append("<PARAM NAME=\"quality\" VALUE=\"high\">")
                      .append("<PARAM NAME=\"bgcolor\" VALUE=\"#FFFFFF\">")
                      .append("<PARAM NAME=\"wmode\" VALUE=\"" + hItem.getWMode() + "\">").append("<EMBED SRC=\"")
                      .append(loc).append("\"").append(addTagProperty(" WMODE", hItem.getWMode(), null))
                      .append(" QUALITY=\"high\"").append(" BGCOLOR=\"#FFFFFF\"").append(" WIDTH=\"")
                      .append(hItem.getWidth()).append("\"").append(" HEIGHT=\"").append(hItem.getHeight()).append("\"")
                      .append(" TYPE=\"application/x-shockwave-flash\"")
                      .append(" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\">")
                      .append("</EMBED></OBJECT>");
        } else {
            htmlBuffer.append("<img src=\"resources/images/media/flash.gif\" />");
        }

        htmlBuffer.append("</div>");

        return htmlBuffer;
    }

    /**
     * DOCUMENT ME!
     *
     * @param pCtx DOCUMENT ME!
     * @param itemToRender DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public StringBuffer renderChildren(WebContext pCtx, UIComponent itemToRender) {
        StringBuffer stringBuffer = new StringBuffer();

        return stringBuffer;
    }

    /**
     * DOCUMENT ME!
     *
     * @param pCtx DOCUMENT ME!
     * @param itemToRender DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public StringBuffer renderEnd(WebContext pCtx, UIComponent itemToRender) {
        StringBuffer stringBuffer = new StringBuffer();

        return stringBuffer;
    }
}
